# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 工具创建-从可运行对象创建工具.py
# @Author: dongguangwen
# @Date  : 2025-03-23 21:38
from langchain_core.language_models import GenericFakeChatModel
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages(
    [("human", "Hello. Please respond in the style of {answer_style}.")]
)

# Placeholder LLM
llm = GenericFakeChatModel(messages=iter(["hello matey"]))

chain = prompt | llm | StrOutputParser()

as_tool = chain.as_tool(
    name="Style responder", description="Description of when to use tool."
)
ret = as_tool.args
print(ret)

"""
{'answer_style': {'title': 'Answer Style', 'type': 'string'}}
"""